package com.lph.util;

import java.io.PrintWriter;
import java.security.Principal;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;
//登录拦截器
public class loginInterceptor implements HandlerInterceptor{
	//执行验证
	/**
	 * return true 验证通过
	 * false 被拦截
	 */
	
	//验证后的方法
	public boolean preHandle(HttpServletRequest req, HttpServletResponse res, Object obj)
			throws Exception {

		//获取session
		HttpSession session=req.getSession();
		//获取会话内容
		Object o=session.getAttribute("loginMen");
		if(o!=null){
			return true;
		}
		PrintWriter out=res.getWriter();
		String str="javascript:alert('未登录或登录信息已过期')";
		res.sendRedirect(req.getContextPath()+"/login.jsp");
		out.write(str);
		return false;
	}

	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		// TODO Auto-generated method stub
		
	}

	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		// TODO Auto-generated method stub
		
	}
	
	
	
}
